import React, { Component } from 'react'
import { connect } from 'react-redux'
import { withRouter } from 'react-router-dom'
import {followStudentByInviteLink} from '../actions/program'
import { Spin } from 'antd'
import { convertContent } from '../constant/lang-util'

class FollowerLinkPageBody extends Component {
  componentDidMount () {
    const code = this.getQueryString('code')
    this.props.followStudentByInviteLink(code)
  }
  getQueryString (name) {
    const reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i')
    const params = this.props.location.search.substr(1).match(reg)
    if (params != null) return unescape(params[2]); return null
  }

  render () {
    return <div style={{textAlign: 'center', paddingTop: '10%'}}>
      <Spin />
      <p>
        <a href='https://school.thoughtworks.cn/learn/program-center/student/index.html#/'>
          {convertContent('返回训练营中心')}
        </a>
      </p>
    </div>
  }
}
const mapDispatchToProps = dispatch => ({
  followStudentByInviteLink: (code) => dispatch(followStudentByInviteLink(code))
})

export default withRouter(connect(null, mapDispatchToProps)(FollowerLinkPageBody))
